local skel = fk.CreateSkill{--定义
  name = "kqf__xixin",
}

local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{--翻译
  ["kqf__xixin"] = "悉心",
  [":kqf__xixin"] = "一名角色的回合开始时，你可以依次弃两张牌，声明第一张牌的类型和第二张牌的花色；本回合结束时，你获得中央区一张花色类型皆与声明相符的牌；若无对应牌，你摸三张牌且此技能本轮失效。",

  ["#kqf__xixin"] = "悉心：你可以依次弃两张牌，声明第一张牌的类型和第二张牌的花色",
  ["#kqf__xixin_2"] = "悉心：依次弃一张牌，声明其花色",
  ["#kqf__xixin_ask"] = "获得其中一张牌",

  ["@kqf__xixin-turn"] = "悉心",

  ["$kqf__xixin1"] = "举止淑德，不失身份。",
  ["$kqf__xixin2"] = "娴雅适度，进退得体。",

}

skel:addAcquireEffect(function (self, player, is_start)--DIYU的中央区加入游戏
  player.room:addSkill("#CenterArea")
end)

skel:addEffect(fk.TurnStart, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and #player:getCardIds("he") > 1
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local _,cid,yn = room:askToChooseCardsAndPlayers(player, {
      min_num = 0,
      max_num = 0,
      min_card_num = 1,
      max_card_num = 1,
      targets = {},
      skill_name = skel.name,
      prompt = "#kqf__xixin",
      cancelable = true,
    })
    if yn then
      event:setCostData(self, {cid = cid})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --1
    local cid = event:getCostData(self).cid
    local type = Fk:getCardById(cid[1]).type
    local text = Fk:translate(Fk:getCardById(cid[1]):getTypeString())
    room:throwCard(cid,skel.name,player,player)
    --2
    _,cid = room:askToChooseCardsAndPlayers(player, {
      min_num = 0,
      max_num = 0,
      min_card_num = 1,
      max_card_num = 1,
      targets = {},
      skill_name = skel.name,
      cancelable = false,
      prompt = "#kqf__xixin_2",
    })
    local suit = Fk:getCardById(cid[1]).suit
    text = Fk:translate(Fk:getCardById(cid[1]):getSuitString(true))..text
    room:throwCard(cid,skel.name,player,player)
    room:setPlayerMark(player,"@kqf__xixin-turn",text)
    room:setPlayerMark(player,"kqf__xixin_type-turn",type)
    room:setPlayerMark(player,"kqf__xixin_suit-turn",suit)
  end,
})

skel:addEffect(fk.TurnEnd, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and player:getMark("kqf__xixin_type-turn") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cids = DIY.getCenterCards(room)
    local type = player:getMark("kqf__xixin_type-turn")
    local suit = player:getMark("kqf__xixin_suit-turn")
    local yn = {}
    for _,cid in ipairs(cids) do
      local card = Fk:getCardById(cid)
      if card.type == type and card.suit == suit then
        table.insert(yn,cid)
      end
    end
    if #yn > 1 then
      --
      local _,cid = room:askToChooseCardsAndPlayers(player, {
        min_card_num = 1,
        max_card_num = 1,
        min_num = 0,
        max_num = 0,
        targets = {},
        pattern = ".|.|.|^(hand,equip)",
        expand_pile = yn,
        skill_name = skel.name,
        prompt = "#kqf__xixin_ask",
        cancelable = false,
      })
      room:moveCardTo(cid, Card.PlayerHand, player, fk.ReasonJustMove, skel.name, nil, false, player)
    elseif #yn > 0 then
      room:moveCardTo(yn, Card.PlayerHand, player, fk.ReasonJustMove, skel.name, nil, false, player)
    else
      --
      room:drawCards(player,3,skel.name)
      room:invalidateSkill(player, skel.name, "-round")
    end
  end,
})

return skel